#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tkinter as tk
from typing import Tuple

from PIL import ImageTk, Image
from PIL.ImageTk import PhotoImage

from AbstractGrid import AbstractGrid
from BasicMap import BasicMap
from a2_solution import Position, Game
from constants import *


class ImageMap(BasicMap):
    def __init__(self, master: tk.Tk, size: Tuple[int, int], **kwargs):
        """
        first call BasicMap.__init__, and init all image, holding to avoid gc
        """
        BasicMap.__init__(self, master,size,**kwargs)
        self.images = {
            PLAYER: PhotoImage(Image.open(IMAGES.get(PLAYER))),
            HOSPITAL: PhotoImage(Image.open(IMAGES.get(HOSPITAL))),
            ZOMBIE: PhotoImage(Image.open(IMAGES.get(ZOMBIE))),
            GARLIC: PhotoImage(Image.open(IMAGES.get(GARLIC))),
            TRACKING_ZOMBIE: PhotoImage(Image.open(IMAGES.get(TRACKING_ZOMBIE))),
            CROSSBOW: PhotoImage(Image.open(IMAGES.get(CROSSBOW))),
            BACK_GROUND: PhotoImage(Image.open(IMAGES.get(BACK_GROUND))),
        }

    def draw_entity(self, position: Position, tile_type: str):
        """
        Draws the entity with tile type at the
        given position using a coloured rectangle with superimposed text identifying the entity.
        Args:
            position:
            tile_type:

        Returns:

        """
        x, y = self.get_position_center(position)
        self.create_image(x, y,image=self.images.get(tile_type))
